# My pseudo code for Exercice 5
# START
#     arr <- READ a list
#     k  <-  READ a number
#     length <-  len(list)
#     advanced_list <- [0]*length
#     Check <- True
#     IF k <=0 then:
#         Check <- False
#         Display" k should be non-negative"
#     END IF
#     IF Check==True then:
#         k <- k % length
#         FOR each item in the list:
#             advanced_list[(i + k) % length]=item
#         END FOR
#     END IF
#     Display"Output: advanced_list"
#     Display"Explanation: The array is rotated {k} steps to the right."
# END

def fun(arr, k):
    length = len(arr)
    if k <= 0 or not isinstance(k, int):
        raise ValueError("Invalid Input")      
    rotated_arr = [0] * length
    k = k % length  
    for i in range(length):
        rotated_arr[(i + k) % length] = arr[i]
    return rotated_arr
print(fun([-1,-100,3,99], 2))
print(fun([1,2,3,4,5,6,7],3))